#include<cstdio>
int min(int a,int b){return a<b?a:b;}
int main()
{
    int n,a,b,s=100000001;
    scanf("%d",&n);
    for(int i=1;i<=3;i++)
    {
        scanf("%d%d",&a,&b);
        if(n%a==0) b=n/a*b;
        else b=(n/a+1)*b;
        s=min(s,b);
    }
    printf("%d",s);
    fclose(stdin);
    fclose(stdout);
    return 0;
}
